package com.hd.platform.server.api.log;


import com.hd.model.BaseReq;
import com.hd.platform.util.DateUtil;
import com.hd.platform.util.EmojiFilterUtil;
import com.hd.platform.util.JsonUtil;
import org.slf4j.Logger;

import java.util.Date;

/**
 * Created by qingshengzheng on 16/7/12.
 */
public class ApiLogger {
    private  static Logger logInfo = LoggerFactory.getApiInvokeLogger(ApiLogger.class);

    public static  void log(String request, Object o) {
        ApiLog apiLog = new ApiLog();
        apiLog.setReq(o);
        apiLog.setTime(DateUtil.getStringDateByDate(new Date()));
        apiLog.setUrl(request);
        String json = JsonUtil.toJson(apiLog);
        //将表情符号转换成*
        json= EmojiFilterUtil.filterEmoji(json);
        logInfo.info(json);
    }
    public static  void log(String request, Object o,String userid) {
        ApiLog apiLog = new ApiLog();
        if(o instanceof BaseReq) {
            BaseReq req = (BaseReq) o;
            apiLog.setUserid(req.getOperuid());
        }
        apiLog.setReq(o);
        apiLog.setUserid(userid);
        apiLog.setTime(DateUtil.getStringDateByDate(new Date()));
        apiLog.setUrl(request);
        String json = JsonUtil.toJson(apiLog);
        logInfo.info(json);

    }
}
